package com.hidt.shop.util;

import org.springframework.core.convert.converter.Converter;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @author Fhy
 * @Title DateConverter
 * @Package com.hdit.shop.util
 * @Description 时间类型转换(String --> sql.Date)
 * @date 2021/1/19 17:05
 */
public class DateConverter implements Converter<String, Date> {

    @Override
    public Date convert(String arg0) {
        System.out.println("自动转换器");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date Udate = null;
        try {
            Udate = sdf.parse(arg0);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Date Sdate = new Date(Udate.getTime());
        return Sdate;
    }

}
